package com.bjsxt;

import java.awt.*;
import javax.swing.*;


public class TeatGame extends JFrame {

    Image ball = Toolkit.getDefaultToolkit().getImage("images/ball.png");

    Image desk = Toolkit.getDefaultToolkit().getImage("images/desk.png");

    double x = 200;

    double y = 200;

    double degree = 3.14/3;

    public void paint(Graphics g) {
        System.out.println("窗口被画了一次");
        g.drawImage(desk,0,0,null);
        g.drawImage(ball,(int)x,(int)y,null);

        x = x+10*Math.cos(degree);
        y = y+10*Math.sin(degree);

        if(y>501-40-30||y<40+40) {
            degree = -degree;
        }

        if(x>856-40-30||x<40) {
            degree = 3.14 - degree;
        }
    }

    //创建窗口
    void launchFrame() {
        setSize(856,501);
        setLocation(100,100);
        setVisible(true);

        //实现绘画窗口
        while(true) {
            repaint();

            try {
                Thread.sleep(40);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }

    }


    public static void main(String[] args) {
        System.out.println("游戏开始了!");
        TeatGame game = new TeatGame();
        game.launchFrame();
    }
}
